package core1;

import processing.core.PApplet;

public class ChordElement extends ChordObject
{
	private boolean queryRunning = false;
	private ChordQuery query = null;
	
	public ChordElement(PApplet parent) {
		super(parent);
		this.parent = parent;
		setPhysics(7f, .5f, .70f);
	}

	public ChordElement(PApplet parent, long hash) {
		
		super(parent,hash);
		this.parent = parent;
		setPhysics(7f, .5f, .70f);
	}
	
	public ChordElement(PApplet parent, long hash, String key, String value) {
		
		super(parent,hash);
		this.parent = parent;
		setPhysics(7f, .5f, .70f);
		
		// TODO: Handle plain key and value
	}
	
	// This is done directly after the constructor
	public void setQuery(ChordQuery query) {
		this.query = query;
		this.queryRunning = true;
	}
	
	@Override
	public void draw(float scale) {
		if (queryRunning && query.isDone()) {
			queryRunning = false;
		} else if (queryRunning) {
			query.draw(scale);
		} else {
			update();
			parent.fill(globals.ElementColor);
			parent.stroke(globals.ElementFrameColor);
			parent.rectMode(PApplet.CENTER);
			parent.strokeWeight(1/scale);
			parent.translate(getXpos(),getYpos());
		
			parent.rect(0, 0, 5/scale, 5/scale);
		}
	}
	
}
